<template>
  <div id="regularstop">  
  <div  style="display:flex;align-items: center;">
            <img class="top_img" src="@/assets/images/a8.png" style="width:35px;height:35px;margin-right:10px;"/>
            <div style="line-height: 40px;font-weight:bold:">休息设置</div>
     </div>
  <el-row>
   <el-col :span="24" style="text-align: right;">         
            <el-button type="primary" class="custom_color_button1" style="margin-bottom:10px;" @click="add_but()" >
              <img class="custom_color_button1_img" src="@/assets/images/but_bg2.png" />增加休息
             </el-button>  
             <el-button type="primary" class="custom_color_button1" style="margin-bottom:10px;"  @click="switch_but()">
               <img class="custom_color_button1_img" src="@/assets/images/but_bg6.png" />
              总休息-<span v-if="close_market_switch == 0">开启</span><span v-if="close_market_switch == 1">关闭</span>
            </el-button>   
            <el-button type="primary" class="custom_color_button1" style="margin-bottom:10px;" @click="stopswitch_but()">
              <img class="custom_color_button1_img" src="@/assets/images/but_bg9.png" />
              休息记录
            </el-button>    
        </el-col>
  </el-row>

    <!-- 渲染数据list -->
   <regularstop-list :list="list" @up_list_fun="list_fun"> </regularstop-list>
      
   <div style="margin-top:20px;text-align: center;">
      <el-pagination
        background
        @current-change="handleCurrentChange"
        :page-size="10"  
        layout="prev, pager, next, jumper"
        :total="count">
      </el-pagination>
    </div>


      <el-dialog title="添加信息" :visible.sync="add_mtk"  width="400px" >
            
        <el-form ref="form"  label-width="80px">  
                <el-form-item label="" label-width="0px" style="margin-left:10px;margin-bottom:0px !important;">
                    <el-date-picker 
                    :picker-options="pickerOptions"  type="date" placeholder="选择日期" format="yyyy-MM-dd" value-format="yyyy-MM-dd"  v-model="form.time"  style="width:100%;"></el-date-picker>
                </el-form-item>
        </el-form>
        
        <div style="text-align: center;width:80%;margin:auto;">
                <el-button type="primary" class="custom_color_button" style="width:80%;margin-top:20px;" @click="add_but_qr">确认</el-button>
        </div>

      </el-dialog>

      
  </div>
</template>

<script>
import RegularstopList from '@/view/Trading/RegularstopList'
export default {
  name: 'regularstop',
  data () {
    return {
        pickerOptions: { // 计费日期的约束条件  //不能选择当前日期之前的（包括现在）
            disabledDate(time) {
              //console.log(this.getNowDate1())
              var date = new Date();
              var seperator1 = "-";
              var year = date.getFullYear();
              var month = date.getMonth() + 1;
              var strDate = date.getDate();
              if (month >= 1 && month <= 9) {
                month = "0" + month;
              }
              if (strDate >= 0 && strDate <= 9) {
                strDate = "0" + strDate;
              }
              var currentdate = year + seperator1 + month + seperator1 + strDate;
              return time.getTime() < new Date(currentdate).getTime()
            }
         },
        add_mtk:false,
        list:[],
        page:1,
        count:0,
        form:{
          time:'',
        },
        close_market_switch:''
 
    }
  },
 components:{
    RegularstopList
  },
  created(){
   
    this.list_fun()
    this.type_fun()
  },
  mounted (){
    
  },
  methods: {   
    type_fun(){
           this.post("/market_close/switchStatus", {
            
	          }).then(res => {
            this.close_market_switch = res.result.close_market_switch
            //console.log(res)
         })
      },
      list_fun(){
          this.post("/market_close/listOfData", {
              page:this.page, 
	        }).then(res => {
            this.count = res.result.count
            this.list = res.result.list
            console.log(res)
         })
      }, 
      add_but(){
         this.add_mtk = true
         this.form.time = ''
      },
      add_but_qr(){
           // console.log(this.form.time)
             this.post("/market_close/create", {
                  daytime_str:this.form.time,
                }).then(res => {
                    if(res.error_code == 0){
                    this.open1(res.result,'success')  //提示框
                    this.add_mtk = false
                    this.list_fun()
                    }else {
                    this.open1(res.message,'warning')
                }

        })
      },
      stopswitch_but(){
         this.$router.push({
          path: '/index/stopswitch',
          query: {
            
          }
        })
      },
      switch_but(){
        // console.log( this.getTime(this.getTime_fm()),"当前时间")
        // console.log(this.getTime('00:00'),"00：00")
        // console.log(this.getTime('04:00'),"04：00")

        if(   this.getTime(this.getTime_fm()) > this.getTime('04:00')  ){
             
            this.$confirm('是否开启/关闭, 是否继续?', '提示', {
              confirmButtonText: '确定',
              cancelButtonText: '取消',
              type: 'warning'
            }).then(() => {    
                    this.post("/market_close/setSwitch", {
                      
                    }).then(res => {

                        if(res.error_code == 0){
                        this.open1(res.result,'success')  //提示框
                        this.type_fun()
                        this.list_fun()
                        }else {
                        this.open1(res.message,'warning')
                    }

                })
            }).catch(() => {
                  this.type_fun()
            });

        }else{
            this.open1("请在00:00-04:00之外操作",'warning')
        }
       
      },
     handleSizeChange(val) {
        console.log(`每页 ${val} 条`);
      },
      handleCurrentChange(val) {
        this.page = val
        this.list_fun()
        console.log(`当前页: ${val}`);
      }
  }
}
</script>


<style scoped>

</style>
